package com.ruoyi.integration.service.impl;

import com.ruoyi.integration.config.WeatherServiceProperties;
import com.ruoyi.integration.response.WeatherResponse;
import com.ruoyi.integration.service.BaseIoTDataService;
import com.ruoyi.integration.service.token.TokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.HashMap;
import java.util.concurrent.ExecutionException;

@Service
public class WeatherStationDataServiceImpl extends BaseIoTDataService {

    @Autowired
    private WeatherServiceProperties weatherServiceProperties;

    private final static Logger logger = LoggerFactory.getLogger(WeatherStationDataServiceImpl.class);

    public WeatherStationDataServiceImpl(WebClient webClient, TokenManager tokenManager) {
        super(webClient, tokenManager);
    }

    public WeatherResponse fetchData(String deviceId) throws ExecutionException {

        String url = weatherServiceProperties.getEndpoint().getDataUrl() + deviceId + "?accessToken=" + getAccessToken("weather");
        logger.info("weather-station-data-service: {}", url);
        logger.info("weather-station-data-service-token: {}", getAccessToken("weather"));
        HashMap<String, String> headers = new HashMap<>();

        return doGet(url, WeatherResponse.class, headers);

    }
}
